var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        classify_data: [],
        store_id: ""
    },
    onLoad: function(t) {
        t.store_id && this.setData({
            store_id: t.store_id
        }), this.getJson();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        wx.reLaunch({
            url: "/packageC/o2o/storeManage/storeManage?store_id=" + this.data.store_id
        });
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getJson: function() {
        var t = this, e = a.getNetAddresss("plugin.store-cashier.frontend.store.goods-category.get-category-by-store-id"), s = {
            store_id: parseInt(t.data.store_id)
        };
        a._postNetWork({
            url: e,
            showToastIn: !1,
            data: s,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    t.setData({
                        classify_data: []
                    });
                    for (var s = 0; s < e.data.list.length; s++) {
                        e.data.list[s].btn_active = !1, e.data.list[s].level_active = !1;
                        for (var i = 0; i < e.data.list[s].childrens.length; i++) e.data.list[s].childrens[i].btn_active = !1, 
                        e.data.list[s].childrens[i].level_active = !1;
                    }
                    t.setData({
                        classify_data: e.data.list
                    }), t.emptyMore();
                } else wx.showToast({
                    icon: "none",
                    title: "暂无商品分类,请添加分类",
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    emptyMore: function() {
        for (var a = 0; a < this.data.classify_data.length; a++) {
            var e;
            this.setData((t(e = {}, "classify_data[" + a + "].btn_active", !1), t(e, "classify_data[" + a + "].level_active", !1), 
            e));
            for (var s = 0; s < this.data.classify_data[a].childrens.length; s++) {
                var i;
                this.setData((t(i = {}, "classify_data[" + a + "].childrens[" + s + "].btn_active", !1), 
                t(i, "classify_data[" + a + "].childrens[" + s + "].level_active", !1), i));
            }
        }
    },
    oneLevel: function(a) {
        var e = a.currentTarget.dataset.index, s = a.currentTarget.dataset.num;
        if (1 == s) 1 == this.data.classify_data[e].level_active ? this.emptyMore() : 0 != this.data.classify_data[e].childrens.length ? (this.emptyMore(), 
        this.setData(t({}, "classify_data[" + e + "].level_active", !0))) : wx.showToast({
            icon: "none",
            title: "此类暂无数据",
            duration: 1500
        }); else if (2 == s) {
            var i;
            if (1 == this.data.classify_data[e].childrens[index2].level_active) this.emptyMore(), 
            this.setData(t({}, "classify_data[" + e + "].level_active", !0)); else if (0 != this.data.classify_data[e].childrens[index2].thirds.length) this.emptyMore(), 
            this.setData((t(i = {}, "classify_data[" + e + "].level_active", !0), t(i, "classify_data[" + e + "].childrens[" + index2 + "].level_active", !0), 
            i)); else wx.showToast({
                icon: "none",
                title: "此类暂无数据",
                duration: 1500
            });
        }
    },
    levelMore: function(a) {
        var e = a.currentTarget.dataset.num, s = a.currentTarget.dataset.index, i = a.currentTarget.dataset.indexc;
        if (1 == e) 1 == this.data.classify_data[s].btn_active ? this.emptyMore() : (this.emptyMore(), 
        this.setData(t({}, "classify_data[" + s + "].btn_active", !0))); else if (2 == e) {
            var d;
            if (1 == this.data.classify_data[s].childrens[i].btn_active) this.emptyMore(), this.setData(t({}, "classify_data[" + s + "].level_active", !0)); else this.emptyMore(), 
            this.setData((t(d = {}, "classify_data[" + s + "].level_active", !0), t(d, "classify_data[" + s + "].childrens[" + i + "].btn_active", !0), 
            d));
        } else if (3 == e) {
            var l, n;
            if (1 == this.data.classify_data[s].childrens[i].thirds[index3].btn_active) this.emptyMore(), 
            this.setData((t(l = {}, "classify_data[" + s + "].level_active", !0), t(l, "classify_data[" + s + "].childrens[" + i + "].level_active", !0), 
            l)); else this.emptyMore(), this.setData((t(n = {}, "classify_data[" + s + "].level_active", !0), 
            t(n, "classify_data[" + s + "].childrens[" + i + "].level_active", !0), t(n, "classify_data[" + s + "].childrens[" + i + "].thirds[" + index3 + "].btn_active", !0), 
            n));
        }
    },
    classifyRoute: function(t) {
        var a = t.currentTarget.dataset.num, e = t.currentTarget.dataset.numc, s = t.currentTarget.dataset.index, i = t.currentTarget.dataset.indexc;
        1 == a ? 2 == e ? wx.navigateTo({
            url: "/packageC/o2o/AddClassify/AddClassify?store_id=" + this.data.store_id + "&classify_id=" + this.data.classify_data[s].id + "&level=" + e
        }) : 3 == e && wx.navigateTo({
            url: "/packageC/o2o/AddClassify/AddClassify?store_id=" + this.data.store_id + "&classify_id=" + this.classify_data[s].childrens[i].id + "&level=" + e
        }) : 2 == a && (1 == e ? wx.navigateTo({
            url: "/packageC/o2o/FirstEdit/FirstEdit?store_id=" + this.data.store_id + "&classify_id=" + this.data.classify_data[s].id + "&level=" + e
        }) : 2 == e ? wx.navigateTo({
            url: "/packageC/o2o/FirstEdit/FirstEdit?store_id=" + this.data.store_id + "&classify_id=" + this.data.classify_data[s].childrens[i].id + "&level=" + e
        }) : 3 == e && wx.navigateTo({
            url: "/packageC/o2o/FirstEdit/FirstEdit?store_id=" + this.data.store_id + "&classify_id=" + this.data.classify_data[s].childrens[i].thirds[index3].id + "&level=" + e
        }));
    },
    deleteClassify: function(t) {
        var e = t.currentTarget.dataset.num, s = t.currentTarget.dataset.index, i = t.currentTarget.dataset.indexc, d = this;
        wx.showModal({
            title: "提示",
            content: "此操作将永久删除该分类, 是否继续?",
            success: function(t) {
                if (t.confirm) {
                    var l = "";
                    if (1 == e) {
                        if (console.log(e), l = d.data.classify_data[s].id, 0 != d.data.classify_data[s].childrens.length) return void wx.showToast({
                            icon: "none",
                            title: "先清空二级分类",
                            duration: 1500
                        });
                    } else 2 == e ? l = d.data.classify_data[s].childrens[i].id : 3 == e && (l = d.data.classify_data[s].childrens[i].thirds[index3].id);
                    var n = {
                        id: l
                    }, r = a.getNetAddresss("plugin.store-cashier.frontend.store.goods-category.del-category");
                    a._postNetWork({
                        url: r,
                        showToastIn: !1,
                        data: n,
                        success: function(t) {
                            var a = t.data;
                            if (1 == a.result) {
                                var l = d.data.classify_data;
                                1 == e ? l.splice(s, 1) : 2 == e ? l[s].childrens.splice(i, 1) : 3 == e && l[s].childrens[i].thirds.splice(index3, 1), 
                                d.setData({
                                    classify_data: l
                                }), wx.showToast({
                                    icon: "none",
                                    title: "删除成功",
                                    duration: 1500
                                });
                            } else wx.showToast({
                                icon: "none",
                                title: a.msg,
                                duration: 1500
                            });
                        },
                        fail: function(t) {}
                    });
                } else t.cancel && wx.showToast({
                    icon: "none",
                    title: "已取消删除",
                    duration: 1500
                });
            }
        });
    },
    addClassify: function() {
        wx.navigateTo({
            url: "/packageC/o2o/AddClassify/AddClassify?store_id=" + this.data.store_id + "&classify_id=add&level=1"
        });
    }
});